<!DOCTYPE html>
<html>

<head>
	<title>流程设计器</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        var path = window.document.location.href;
        var pathName = window.document.location.pathname;
        var hostPath = path.substring(0, path.indexOf(pathName));
        var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
        document.write('<scr' + 'ipt src="' + projectName + '/js/html/header.js"></scr' + 'ipt>');
    </script>
</head>

<body>
    <table id="dg" style="width: auto; height: auto" fitColumns="true">
        <thead>
            <tr>
                <th field="id" align="right" width="100" data-options="
				sortable:true,
				remoteSort:false
				">流程ID</th>
                <th field="name" align="right" width="100" data-options="
				sortable:true,
				remoteSort:false
				">流程名称</th>
                <th field="key" align="right" width="100" data-options="
				sortable:true,
				remoteSort:false
				">流程编号</th>
                <th field="version" align="right" width="100" data-options="
				sortable:true,
				remoteSort:false
				">流程版本</th>
                <th field="lastUpdateTime" align="right" width="100" data-options="
				sortable:true,
				remoteSort:false
                ">最后修改时间</th>
                <th field="deploymentId" align="right" width="100" data-options="
				sortable:true,
				remoteSort:false
                ">部署ID</th>
            </tr>
        </thead>
    </table>
    <div id="dg-buttons" style="height: auto">
        <div style="margin-bottom:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true"
                onclick="createDesigner()">新建 </a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true"
                onclick="deleteDesigner()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"
                onclick="modifyDesigner()">修改</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"
                onclick="releaseDesigner()">发布模型 </a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-export',plain:true"
                onclick="exportDesigner()">导出模型 </a>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import',plain:true"
                onclick="importDesigner()">导入模型 </a>
            <input class="easyui-filebox" id="bpmnfile" style="width:200px" data-options="accept:'.bpmn',buttonText:'选择模型'">
        </div>
        <div>
            <span>&nbsp;&nbsp;&nbsp;&nbsp;选择:</span>
            <input type="text" id="searchKey" name="searchKey" class="easyui-combobox" />
            <span>等于:</span>
            <input type="text" id="searchValue" name="searchValue" class="easyui-validatebox" />
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="dgop.find()">查询</a>
        </div>
    </div>
    <!--隐藏的文本框-->
    <div id="win" class="easyui-window" title="工作流任务" style="width: 800px; height: 450px" closed="true"
        data-options="iconCls:'icon-save',modal:true">
        <div id="centers" data-options="region:'center',title:'center title'"
            style="padding: 5px; background: #eee; height: 90%"></div>
    </div>

    <div id="dlg-Details" class="easyui-window" closed="true" style="width: 730px; height: 280px; padding: 10px 10px;">
    </div>
    <script>
        var initd = {
            queryDataURL: "/workflow/designer/match/all",//查询URL
            saveDataURL: "",//保存URL
            dg: $('#dg')
        };

        function createDesigner() {
            var createURL = "/workflow/designer/create";
            $.ajax({
                type: "POST",
                dataType: "json",
                contentType : "application/json;charset=utf-8",
                url: projectName + createURL,
                beforeSend: function () {
                },
                success: function (result) {
                    if (result.success) {
                        openDesigner(result.extValues.id);
                        $("#dg").datagrid("reload");
                    } else {
                        if (!jQuery.isEmptyObject(result.message)) {
                            $.messager.alert("系统错误", result.message);
                        } else {
                            $.messager.alert("系统错误", result);
                        }
                        return;
                    }
                },
                error: function (err, status) {
                    errorMsgAlert(err);
                    $.messager.progress("close");
                }
            });
        }

        function openDesigner(processkey) {
            var designerUrl = projectName+"/modeler.html?modelId="+processkey;
            var feature = 'top=0, left=0,toolbar=no,menubar=yes, scrollbars=yes, resizable=yes,location=no,status=no,channelmode = yes';
            var newwindows = window.open(designerUrl, "", feature);
            newwindows.moveTo(0, 0); //将新页面打开位置定位在屏幕左上角
            newwindows.resizeTo(screen.width, screen.height); //设置新页面的大小
            if (newwindows != null) {
                newwindows.focus();//新页面获得焦点
            }

        }
        
        function deleteDesigner() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的数据！");
                return;
            }
            
            var removeData = selectedRows[0]

            var deleteURL = "/workflow/designer/"+removeData.id;

            $.messager.progress();
            
            $.messager.confirm("系统提示", "您确定要删除这<font color=red>" + selectedRows.length + "</font>条数据吗？", function (r) {
                if (r) {
                	$.ajax({
                        type: "DELETE",
                        dataType: "json",
                        contentType : "application/json;charset=utf-8",
                        url: projectName + deleteURL,
                        success : function(result) {
                            $.messager.progress("close");
                			if (result.success) {
        	                    $.messager.alert("系统提示", "数据已成功删除！");
        	                    $("#dg").datagrid("reload");
        	                } else {
        	                	if(!jQuery.isEmptyObject(result.message)){
        	                		$.messager.alert("系统错误", result.message);
        	                	}else{
        	                		$.messager.alert("系统错误", result);
        	                	}
        	                    return;
        	                }
                        },
                		error:function(err, status){
                			errorMsgAlert(err);
                			$.messager.progress("close");
                		}
                    });
                }
            });
        }

        function modifyDesigner() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择数据！");
                return;
            }
            var modifyData = selectedRows[0]
            openDesigner(modifyData.id);
        }

        function releaseDesigner() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择数据！");
                return;
            }
            var releaseData = selectedRows[0]

            var releaseURL = "/workflow/designer/"+releaseData.id+"/deployment";

            $.messager.progress();
            $.ajax({
                type: "POST",
                dataType: "json",
                contentType : "application/json;charset=utf-8",
                url: projectName + releaseURL,
                success : function(result) {
                    $.messager.progress("close");
        			if (result.success) {
	                    $.messager.alert("系统提示", "数据已成功发布 ！");
	                    $("#dg").datagrid("reload");
	                } else {
	                	if(!jQuery.isEmptyObject(result.message)){
	                		$.messager.alert("系统错误", result.message);
	                	}else{
	                		$.messager.alert("系统错误", result);
	                	}
	                    return;
	                }
                },
        		error:function(err, status){
        			errorMsgAlert(err);
        			$.messager.progress("close");
        		}
            });
        }
        
        function exportDesigner() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择数据！");
                return;
            }
            var releaseData = selectedRows[0]

            var releaseURL = "/workflow/designer/"+releaseData.id+"/export";

            $.messager.progress();
            $.ajax({
                type: "POST",
                dataType: "json",
                contentType : "application/json;charset=utf-8",
                url: projectName + releaseURL,
                success : function(result) {
                    $.messager.progress("close");
        			if (result.success) {
        				downloadFile(result.entity)
	                } else {
	                	if(!jQuery.isEmptyObject(result.message)){
	                		$.messager.alert("系统错误", result.message);
	                	}else{
	                		$.messager.alert("系统错误", result);
	                	}
	                    return;
	                }
                },
        		error:function(err, status){
        			errorMsgAlert(err);
        			$.messager.progress("close");
        		}
            });
        }
        
        function importDesigner() {
            var releaseURL = "/workflow/designer/import";
            
            var fileName = $("#bpmnfile").filebox('getValue');
            var files = $("#bpmnfile").next().find('input[type=file]')[0].files;
            if(!fileName){
            	$.messager.alert("系统提示", "请先选择模型文件 ！");
            	return false;
            }
            
            var formData = new FormData();
            formData.append("bpmnfile",files[0]);
            formData.append("fileName",fileName);
            
            $.messager.progress();
            $.ajax({
                url: projectName + releaseURL,
                type:'post',
                data: formData,
                contentType: false,
                processData: false,
                success : function(result) {
                    $.messager.progress("close");
        			if (result.success) {
	                    $.messager.alert("系统提示", "数据已成功发布 ！");
	                    $("#dg").datagrid("reload");
	                } else {
	                	if(!jQuery.isEmptyObject(result.message)){
	                		$.messager.alert("系统错误", result.message);
	                	}else{
	                		$.messager.alert("系统错误", result);
	                	}
	                    return;
	                }
                },
        		error:function(err, status){
        			errorMsgAlert(err);
        			$.messager.progress("close");
        		}
            });
            $('#bpmnfile').filebox('clear');//上传成功后清空里面的值
        }

    </script>
</body>

</html>

